class OrganizationModel {
  final int id;
  final String name;
  final int level;
  final String contactPerson;
  final String contactInfo;
  final String remark;
  final int parentId;
  final String introduction;
  final String params;
  final String region;
  final int operatorId;
  final int salesId;
  final String licenseInfo;
  final DateTime? contractExpireAt;
  final bool isActive;
  final DateTime createdAt;
  final DateTime updatedAt;
  final DateTime? deletedAt;

  OrganizationModel({
    required this.id,
    required this.name,
    required this.level,
    required this.contactPerson,
    required this.contactInfo,
    required this.remark,
    required this.parentId,
    required this.introduction,
    required this.params,
    required this.region,
    required this.operatorId,
    required this.salesId,
    required this.licenseInfo,
    this.contractExpireAt,
    required this.isActive,
    required this.createdAt,
    required this.updatedAt,
    this.deletedAt,
  });

  factory OrganizationModel.fromJson(Map<String, dynamic> json) {
    return OrganizationModel(
      id: json['id'] as int,
      name: json['name'] as String,
      level: json['level'] as int,
      contactPerson: json['contact_person'] as String? ?? '',
      contactInfo: json['contact_info'] as String? ?? '',
      remark: json['remark'] as String? ?? '',
      parentId: json['parent_id'] as int? ?? 0,
      introduction: json['introduction'] as String? ?? '',
      params: json['params'] as String? ?? '',
      region: json['region'] as String? ?? '',
      operatorId: json['operator_id'] as int? ?? 0,
      salesId: json['sales_id'] as int? ?? 0,
      licenseInfo: json['license_info'] as String? ?? '',
      contractExpireAt: json['contract_expire_at'] != null ? DateTime.parse(json['contract_expire_at'] as String) : null,
      isActive: json['deleted_at'] == null,
      createdAt: DateTime.parse(json['created_at'] as String),
      updatedAt: DateTime.parse(json['updated_at'] as String),
      deletedAt: json['deleted_at'] != null ? DateTime.parse(json['deleted_at'] as String) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'level': level,
      'contact_person': contactPerson,
      'contact_info': contactInfo,
      'remark': remark,
      'parent_id': parentId,
      'introduction': introduction,
      'params': params,
      'region': region,
      'operator_id': operatorId,
      'sales_id': salesId,
      'license_info': licenseInfo,
      'contract_expire_at': contractExpireAt?.toIso8601String(),
    };
  }
}